package com.tlgen.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.tlgen.R;
import com.tlgen.bean.Credit;
import com.xuexiang.xui.widget.textview.supertextview.SuperTextView;

import java.util.ArrayList;

public class ProgressAdapter extends RecyclerView.Adapter<ProgressAdapter.myViewHodler> {
    private Context context;
    private ArrayList<Credit> creditArrayList;

    //构造方法，传入数据
    public ProgressAdapter(Context context, ArrayList<Credit> creditArrayList){
        this.context = context;
        this.creditArrayList = creditArrayList;
    }

    @Override
    public ProgressAdapter.myViewHodler onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = View.inflate(context, R.layout.activity_progress_item, null);
        return new ProgressAdapter.myViewHodler(itemView);
    }

    @Override
    public void onBindViewHolder(ProgressAdapter.myViewHodler holder, int position) {
        Credit credit = creditArrayList.get(position);
        holder.st_duringYear.setCenterString(credit.getDuringYear() + " 年度");
        // 先已有字符串，确定它是有的，如果是先拿数据，只要数据为空就object null
        if ("通过".equals(credit.getCreditStatus())) {
            holder.p2.setImageResource(R.drawable.checked);
        } else {
            holder.p2.setImageResource(R.drawable.nochecked);
        }
        if ("已审批".equals(credit.getCountyCheckStatus())) {
            holder.p3.setImageResource(R.drawable.checked);
        } else {
            holder.p3.setImageResource(R.drawable.nochecked);
        }
        if ("已审批".equals(credit.getIsBankCheck())) {
            holder.p4.setImageResource(R.drawable.checked);
        } else {
            holder.p4.setImageResource(R.drawable.nochecked);
        }
        if ("已发放".equals(credit.getIsIssue())) {
            holder.p5.setImageResource(R.drawable.checked);
        } else {
            holder.p5.setImageResource(R.drawable.nochecked);
        }
    }

    @Override
    public int getItemCount() {
        return creditArrayList.size();
    }

    class myViewHodler extends RecyclerView.ViewHolder {
        SuperTextView st_duringYear;
        ImageView p2;
        ImageView p3;
        ImageView p4;
        ImageView p5;
        public myViewHodler(View itemView) {
            super(itemView);
            st_duringYear = (SuperTextView) itemView.findViewById(R.id.st_duringYear);
            p2 = itemView.findViewById(R.id.p2);
            p3 = itemView.findViewById(R.id.p3);
            p4 = itemView.findViewById(R.id.p4);
            p5 = itemView.findViewById(R.id.p5);
        }
    }
}
